﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationScopeResourceItem : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem
    {
        #region Public Members

        #region AccessLevel

        private global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel _AccessLevel;
        partial void OnBeforeAccessLevelPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel> eventData);
        partial void OnAfterAccessLevelPropertyChanged();
        public global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel AccessLevel
        { 
            get
            {
                return _AccessLevel;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AccessLevel = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel>(value, _AccessLevel);
                    OnBeforeAccessLevelPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AccessLevel", eventData.Value, true, true);
                        OnAfterAccessLevelPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Actions

        private string _Actions;
        partial void OnBeforeActionsPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterActionsPropertyChanged();
        public string Actions
        { 
            get
            {
                return _Actions;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Actions = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Actions);
                    OnBeforeActionsPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Actions", eventData.Value, true, true);
                        OnAfterActionsPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region AuthorizationScopeId

        private long _AuthorizationScopeId;
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        public long AuthorizationScopeId
        { 
            get
            {
                return _AuthorizationScopeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AuthorizationScopeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _AuthorizationScopeId);
                    OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true);
                        OnAfterAuthorizationScopeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region AuthorizationScopeResourceItemId

        private System.Nullable<long> _AuthorizationScopeResourceItemId;
        partial void OnBeforeAuthorizationScopeResourceItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterAuthorizationScopeResourceItemIdPropertyChanged();
        public System.Nullable<long> AuthorizationScopeResourceItemId
        { 
            get
            {
                return _AuthorizationScopeResourceItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AuthorizationScopeResourceItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _AuthorizationScopeResourceItemId);
                    OnBeforeAuthorizationScopeResourceItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AuthorizationScopeResourceItemId", eventData.Value, true, true);
                        OnAfterAuthorizationScopeResourceItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsEnabled

        private bool _IsEnabled;
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        { 
            get
            {
                return _IsEnabled;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsEnabled = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                    OnBeforeIsEnabledPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsEnabled", eventData.Value, true, true);
                        OnAfterIsEnabledPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Resource

        private string _Resource;
        partial void OnBeforeResourcePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterResourcePropertyChanged();
        public string Resource
        { 
            get
            {
                return _Resource;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Resource = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Resource);
                    OnBeforeResourcePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Resource", eventData.Value, true, true);
                        OnAfterResourcePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ResourceItemId

        private string _ResourceItemId;
        partial void OnBeforeResourceItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterResourceItemIdPropertyChanged();
        public string ResourceItemId
        { 
            get
            {
                return _ResourceItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ResourceItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ResourceItemId);
                    OnBeforeResourceItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ResourceItemId", eventData.Value, true, true);
                        OnAfterResourceItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SubActions

        private string _SubActions;
        partial void OnBeforeSubActionsPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSubActionsPropertyChanged();
        public string SubActions
        { 
            get
            {
                return _SubActions;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SubActions = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SubActions);
                    OnBeforeSubActionsPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SubActions", eventData.Value, true, true);
                        OnAfterSubActionsPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public AuthorizationScope AuthorizationScope { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public AuthorizationScopeResourceItemClaimCollectionItem AuthorizationScopeResourceItemClaims { get; set; }
        #region LoadAuthorizationScopeResourceItemClaims

        public void LoadAuthorizationScopeResourceItemClaims(AuthorizationScopeResourceItemClaimCollectionItem value)
        {
            LoadInstanceField("AuthorizationScopeResourceItemClaims", value, true, false);
        }

        #endregion
        #region LoadAuthorizationScopeResourceItemClaimsAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItemClaimCollectionItem> LoadAuthorizationScopeResourceItemClaimsAsync()
        {
            return await LoadAuthorizationScopeResourceItemClaimsAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItemClaimCollectionItem> LoadAuthorizationScopeResourceItemClaimsAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceItemClaimField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceItemClaimRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.LoadAuthorizationScopeResourceItemClaimsAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.AuthorizationScopeResourceItemClaims;
        }

        #endregion
        #region LoadAuthorizationScopeAsync

        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync()
        {
            return await LoadAuthorizationScopeAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.LoadAuthorizationScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.AuthorizationScope;
        }
        public AuthorizationScope LoadAuthorizationScope(AuthorizationScope item)
        {
            LoadInstanceField("AuthorizationScope", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AuthorizationScopeResourceItem Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Copy(this);
        }
        public AuthorizationScopeResourceItem Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem item)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItem> SaveItemAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItem> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItem> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeResourceItem> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeResourceItemManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Initialize(this, settings);
        }

        #endregion

        #region IAuthorizationScopeResourceItem Members

        global::Sidvall.AuthorizationManager.Data.ResourceAccessLevel global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.AccessLevel
        {
            get
            {
                return this._AccessLevel;
            }
            set
            {
                this._AccessLevel = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.Actions
        {
            get
            {
                return this._Actions;
            }
            set
            {
                this._Actions = value;
            }
        }
        long global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        System.Nullable<long> global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.AuthorizationScopeResourceItemId
        {
            get
            {
                return this._AuthorizationScopeResourceItemId;
            }
            set
            {
                this._AuthorizationScopeResourceItemId = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.Resource
        {
            get
            {
                return this._Resource;
            }
            set
            {
                this._Resource = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.ResourceItemId
        {
            get
            {
                return this._ResourceItemId;
            }
            set
            {
                this._ResourceItemId = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.SubActions
        {
            get
            {
                return this._SubActions;
            }
            set
            {
                this._SubActions = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.IAuthorizationScope global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.AuthorizationScope
        {
            get
            {
                return this.AuthorizationScope;
            }
            set
            {
                this.AuthorizationScope = (AuthorizationScope)value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItemClaim> global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.AuthorizationScopeResourceItemClaims
        {
            get
            {
                if (this.AuthorizationScopeResourceItemClaims != null)
                    return this.AuthorizationScopeResourceItemClaims.Items;
                return null;
            }
        }
        void global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItem.SetAuthorizationScopeResourceItemClaims(Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceItemClaim> items)
        {
            this.AuthorizationScopeResourceItemClaims = (AuthorizationScopeResourceItemClaimCollectionItem)items;
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScopeResourceItem()
        {
        }
        public AuthorizationScopeResourceItem(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AuthorizationScopeResourceItem(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeResourceItemManager.Initialize(this);
        }

        #endregion
    }
}